// Copyright (c) Lawrence Livermore National Security, LLC and other VisIt
// Project developers.  See the top-level LICENSE file for dates and other
// details.  No copyright assignment is required to contribute to VisIt.

#include <PyavtSubsetsMetaData.h>
#include <ObserverToCallback.h>
#include <stdio.h>
#include <Py2and3Support.h>
#include <PyNameschemeAttributes.h>

// ****************************************************************************
// Module: PyavtSubsetsMetaData
//
// Purpose:
//   Information about a particular category of subsets of a mesh (even for material subsets)
//
// Note:       Autogenerated by xml2python. Do not modify by hand!
//
// Programmer: xml2python
// Creation:   omitted
//
// ****************************************************************************

//
// This struct contains the Python type information and a avtSubsetsMetaData.
//
struct avtSubsetsMetaDataObject
{
    PyObject_HEAD
    avtSubsetsMetaData *data;
    bool        owns;
    PyObject   *parent;
};

//
// Internal prototypes
//
static PyObject *NewavtSubsetsMetaData(int);
std::string
PyavtSubsetsMetaData_ToString(const avtSubsetsMetaData *atts, const char *prefix, const bool forLogging)
{
    std::string str;
    char tmpStr[1000];

    str = PyavtVarMetaData_ToString(atts, prefix, forLogging);

    snprintf(tmpStr, 1000, "%scatName = \"%s\"\n", prefix, atts->GetCatName().c_str());
    str += tmpStr;
    snprintf(tmpStr, 1000, "%scatCount = %d\n", prefix, atts->GetCatCount());
    str += tmpStr;
    { // new scope
        std::string objPrefix(prefix);
        objPrefix += "nameScheme.";
        str += PyNameschemeAttributes_ToString(&atts->GetNameScheme(), objPrefix.c_str(), forLogging);
    }
    {   const stringVector &colorScheme = atts->colorScheme;
        snprintf(tmpStr, 1000, "%scolorScheme = (", prefix);
        str += tmpStr;
        for(size_t i = 0; i < colorScheme.size(); ++i)
        {
            snprintf(tmpStr, 1000, "\"%s\"", colorScheme[i].c_str());
            str += tmpStr;
            if(i < colorScheme.size() - 1)
            {
                snprintf(tmpStr, 1000, ", ");
                str += tmpStr;
            }
        }
        snprintf(tmpStr, 1000, ")\n");
        str += tmpStr;
    }
    {   const intVector &setsToChunksMaps = atts->GetSetsToChunksMaps();
        snprintf(tmpStr, 1000, "%ssetsToChunksMaps = (", prefix);
        str += tmpStr;
        for(size_t i = 0; i < setsToChunksMaps.size(); ++i)
        {
            snprintf(tmpStr, 1000, "%d", setsToChunksMaps[i]);
            str += tmpStr;
            if(i < setsToChunksMaps.size() - 1)
            {
                snprintf(tmpStr, 1000, ", ");
                str += tmpStr;
            }
        }
        snprintf(tmpStr, 1000, ")\n");
        str += tmpStr;
    }
    {   const intVector &graphEdges = atts->GetGraphEdges();
        snprintf(tmpStr, 1000, "%sgraphEdges = (", prefix);
        str += tmpStr;
        for(size_t i = 0; i < graphEdges.size(); ++i)
        {
            snprintf(tmpStr, 1000, "%d", graphEdges[i]);
            str += tmpStr;
            if(i < graphEdges.size() - 1)
            {
                snprintf(tmpStr, 1000, ", ");
                str += tmpStr;
            }
        }
        snprintf(tmpStr, 1000, ")\n");
        str += tmpStr;
    }
    if(atts->isChunkCat)
        snprintf(tmpStr, 1000, "%sisChunkCat = 1\n", prefix);
    else
        snprintf(tmpStr, 1000, "%sisChunkCat = 0\n", prefix);
    str += tmpStr;
    if(atts->isMaterialCat)
        snprintf(tmpStr, 1000, "%sisMaterialCat = 1\n", prefix);
    else
        snprintf(tmpStr, 1000, "%sisMaterialCat = 0\n", prefix);
    str += tmpStr;
    if(atts->isUnionOfChunks)
        snprintf(tmpStr, 1000, "%sisUnionOfChunks = 1\n", prefix);
    else
        snprintf(tmpStr, 1000, "%sisUnionOfChunks = 0\n", prefix);
    str += tmpStr;
    if(atts->hasPartialCells)
        snprintf(tmpStr, 1000, "%shasPartialCells = 1\n", prefix);
    else
        snprintf(tmpStr, 1000, "%shasPartialCells = 0\n", prefix);
    str += tmpStr;
    const char *decompMode_names = "NONE, Cover, Partition";
    switch (atts->decompMode)
    {
      case avtSubsetsMetaData::None:
          snprintf(tmpStr, 1000, "%sdecompMode = %sNONE  # %s\n", prefix, prefix, decompMode_names);
          str += tmpStr;
          break;
      case avtSubsetsMetaData::Cover:
          snprintf(tmpStr, 1000, "%sdecompMode = %sCover  # %s\n", prefix, prefix, decompMode_names);
          str += tmpStr;
          break;
      case avtSubsetsMetaData::Partition:
          snprintf(tmpStr, 1000, "%sdecompMode = %sPartition  # %s\n", prefix, prefix, decompMode_names);
          str += tmpStr;
          break;
      default:
          break;
    }

    snprintf(tmpStr, 1000, "%smaxTopoDim = %d\n", prefix, atts->maxTopoDim);
    str += tmpStr;
    return str;
}

static PyObject *
avtSubsetsMetaData_Notify(PyObject *self, PyObject *args)
{
    avtSubsetsMetaDataObject *obj = (avtSubsetsMetaDataObject *)self;
    obj->data->Notify();
    Py_INCREF(Py_None);
    return Py_None;
}

/*static*/ PyObject *
avtSubsetsMetaData_SetCatName(PyObject *self, PyObject *args)
{
    avtSubsetsMetaDataObject *obj = (avtSubsetsMetaDataObject *)self;

    PyObject *packaged_args = 0;

    // Handle args packaged as first member of a tuple of size one
    // if we think the unpackaged args matches our needs
    if (PySequence_Check(args) && PySequence_Size(args) == 1)
    {
        packaged_args = PySequence_GetItem(args, 0);
        if (PyUnicode_Check(packaged_args))
            args = packaged_args;
    }

    if (!PyUnicode_Check(args))
    {
        Py_XDECREF(packaged_args);
        return PyErr_Format(PyExc_TypeError, "arg is not a unicode string");
    }

    char const *val = PyUnicode_AsUTF8(args);
    std::string cval = std::string(val);

    if (val == 0 && PyErr_Occurred())
    {
        Py_XDECREF(packaged_args);
        PyErr_Clear();
        return PyErr_Format(PyExc_TypeError, "arg not interpretable as utf8 string");
    }

    Py_XDECREF(packaged_args);

    // Set the catName in the object.
    obj->data->SetCatName(cval);

    Py_INCREF(Py_None);
    return Py_None;
}

/*static*/ PyObject *
avtSubsetsMetaData_GetCatName(PyObject *self, PyObject *args)
{
    avtSubsetsMetaDataObject *obj = (avtSubsetsMetaDataObject *)self;
    PyObject *retval = PyString_FromString(obj->data->GetCatName().c_str());
    return retval;
}

/*static*/ PyObject *
avtSubsetsMetaData_SetCatCount(PyObject *self, PyObject *args)
{
    avtSubsetsMetaDataObject *obj = (avtSubsetsMetaDataObject *)self;

    PyObject *packaged_args = 0;

    // Handle args packaged into a tuple of size one
    // if we think the unpackaged args matches our needs
    if (PySequence_Check(args) && PySequence_Size(args) == 1)
    {
        packaged_args = PySequence_GetItem(args, 0);
        if (PyNumber_Check(packaged_args))
            args = packaged_args;
    }

    if (PySequence_Check(args))
    {
        Py_XDECREF(packaged_args);
        return PyErr_Format(PyExc_TypeError, "expecting a single number arg");
    }

    if (!PyNumber_Check(args))
    {
        Py_XDECREF(packaged_args);
        return PyErr_Format(PyExc_TypeError, "arg is not a number type");
    }

    long val = PyLong_AsLong(args);
    int cval = int(val);

    if (val == -1 && PyErr_Occurred())
    {
        Py_XDECREF(packaged_args);
        PyErr_Clear();
        return PyErr_Format(PyExc_TypeError, "arg not interpretable as C++ int");
    }
    if (fabs(double(val))>1.5E-7 && fabs((double(long(cval))-double(val))/double(val))>1.5E-7)
    {
        Py_XDECREF(packaged_args);
        return PyErr_Format(PyExc_ValueError, "arg not interpretable as C++ int");
    }

    Py_XDECREF(packaged_args);

    // Set the catCount in the object.
    obj->data->SetCatCount(cval);

    Py_INCREF(Py_None);
    return Py_None;
}

/*static*/ PyObject *
avtSubsetsMetaData_GetCatCount(PyObject *self, PyObject *args)
{
    avtSubsetsMetaDataObject *obj = (avtSubsetsMetaDataObject *)self;
    PyObject *retval = PyInt_FromLong(long(obj->data->GetCatCount()));
    return retval;
}

/*static*/ PyObject *
avtSubsetsMetaData_SetNameScheme(PyObject *self, PyObject *args)
{
    avtSubsetsMetaDataObject *obj = (avtSubsetsMetaDataObject *)self;

    PyObject *newValue = NULL;
    if(!PyArg_ParseTuple(args, "O", &newValue))
        return NULL;
    if(!PyNameschemeAttributes_Check(newValue))
        return PyErr_Format(PyExc_TypeError, "Field nameScheme can be set only with NameschemeAttributes objects");

    obj->data->SetNameScheme(*PyNameschemeAttributes_FromPyObject(newValue));

    Py_INCREF(Py_None);
    return Py_None;
}

/*static*/ PyObject *
avtSubsetsMetaData_GetNameScheme(PyObject *self, PyObject *args)
{
    avtSubsetsMetaDataObject *obj = (avtSubsetsMetaDataObject *)self;
    // Since the new object will point to data owned by this object,
    // we need to increment the reference count.
    Py_INCREF(self);

    PyObject *retval = PyNameschemeAttributes_Wrap(&obj->data->GetNameScheme());
    // Set the object's parent so the reference to the parent can be decref'd
    // when the child goes out of scope.
    PyNameschemeAttributes_SetParent(retval, self);

    return retval;
}

/*static*/ PyObject *
avtSubsetsMetaData_SetColorScheme(PyObject *self, PyObject *args)
{
    avtSubsetsMetaDataObject *obj = (avtSubsetsMetaDataObject *)self;

    stringVector vec;

    if (PyUnicode_Check(args))
    {
        char const *val = PyUnicode_AsUTF8(args);
        std::string cval = std::string(val);
        if (val == 0 && PyErr_Occurred())
        {
            PyErr_Clear();
            return PyErr_Format(PyExc_TypeError, "arg not interpretable as C++ string");
        }
        vec.resize(1);
        vec[0] = cval;
    }
    else if (PySequence_Check(args))
    {
        vec.resize(PySequence_Size(args));
        for (Py_ssize_t i = 0; i < PySequence_Size(args); i++)
        {
            PyObject *item = PySequence_GetItem(args, i);

            if (!PyUnicode_Check(item))
            {
                Py_DECREF(item);
                return PyErr_Format(PyExc_TypeError, "arg %d is not a unicode string", (int) i);
            }

            char const *val = PyUnicode_AsUTF8(item);
            std::string cval = std::string(val);

            if (val == 0 && PyErr_Occurred())
            {
                Py_DECREF(item);
                PyErr_Clear();
                return PyErr_Format(PyExc_TypeError, "arg %d not interpretable as C++ string", (int) i);
            }
            Py_DECREF(item);

            vec[i] = cval;
        }
    }
    else
        return PyErr_Format(PyExc_TypeError, "arg(s) must be one or more string(s)");

    obj->data->colorScheme = vec;
    // Mark the colorScheme in the object as modified.
    obj->data->SelectAll();

    Py_INCREF(Py_None);
    return Py_None;
}

/*static*/ PyObject *
avtSubsetsMetaData_GetColorScheme(PyObject *self, PyObject *args)
{
    avtSubsetsMetaDataObject *obj = (avtSubsetsMetaDataObject *)self;
    // Allocate a tuple the with enough entries to hold the colorScheme.
    const stringVector &colorScheme = obj->data->colorScheme;
    PyObject *retval = PyTuple_New(colorScheme.size());
    for(size_t i = 0; i < colorScheme.size(); ++i)
        PyTuple_SET_ITEM(retval, i, PyString_FromString(colorScheme[i].c_str()));
    return retval;
}

/*static*/ PyObject *
avtSubsetsMetaData_SetSetsToChunksMaps(PyObject *self, PyObject *args)
{
    avtSubsetsMetaDataObject *obj = (avtSubsetsMetaDataObject *)self;

    intVector vec;

    if (PyNumber_Check(args))
    {
        long val = PyLong_AsLong(args);
        int cval = int(val);
        if (val == -1 && PyErr_Occurred())
        {
            PyErr_Clear();
            return PyErr_Format(PyExc_TypeError, "number not interpretable as C++ int");
        }
        if (fabs(double(val))>1.5E-7 && fabs((double(long(cval))-double(val))/double(val))>1.5E-7)
            return PyErr_Format(PyExc_ValueError, "number not interpretable as C++ int");
        vec.resize(1);
        vec[0] = cval;
    }
    else if (PySequence_Check(args) && !PyUnicode_Check(args))
    {
        vec.resize(PySequence_Size(args));
        for (Py_ssize_t i = 0; i < PySequence_Size(args); i++)
        {
            PyObject *item = PySequence_GetItem(args, i);

            if (!PyNumber_Check(item))
            {
                Py_DECREF(item);
                return PyErr_Format(PyExc_TypeError, "arg %d is not a number type", (int) i);
            }

            long val = PyLong_AsLong(item);
            int cval = int(val);

            if (val == -1 && PyErr_Occurred())
            {
                Py_DECREF(item);
                PyErr_Clear();
                return PyErr_Format(PyExc_TypeError, "arg %d not interpretable as C++ int", (int) i);
            }
            if (fabs(double(val))>1.5E-7 && fabs((double(long(cval))-double(val))/double(val))>1.5E-7)
            {
                Py_DECREF(item);
                return PyErr_Format(PyExc_ValueError, "arg %d not interpretable as C++ int", (int) i);
            }
            Py_DECREF(item);

            vec[i] = cval;
        }
    }
    else
        return PyErr_Format(PyExc_TypeError, "arg(s) must be one or more ints");

    obj->data->GetSetsToChunksMaps() = vec;
    // Mark the setsToChunksMaps in the object as modified.
    obj->data->SelectSetsToChunksMaps();

    Py_INCREF(Py_None);
    return Py_None;
}

/*static*/ PyObject *
avtSubsetsMetaData_GetSetsToChunksMaps(PyObject *self, PyObject *args)
{
    avtSubsetsMetaDataObject *obj = (avtSubsetsMetaDataObject *)self;
    // Allocate a tuple the with enough entries to hold the setsToChunksMaps.
    const intVector &setsToChunksMaps = obj->data->GetSetsToChunksMaps();
    PyObject *retval = PyTuple_New(setsToChunksMaps.size());
    for(size_t i = 0; i < setsToChunksMaps.size(); ++i)
        PyTuple_SET_ITEM(retval, i, PyInt_FromLong(long(setsToChunksMaps[i])));
    return retval;
}

/*static*/ PyObject *
avtSubsetsMetaData_SetGraphEdges(PyObject *self, PyObject *args)
{
    avtSubsetsMetaDataObject *obj = (avtSubsetsMetaDataObject *)self;

    intVector vec;

    if (PyNumber_Check(args))
    {
        long val = PyLong_AsLong(args);
        int cval = int(val);
        if (val == -1 && PyErr_Occurred())
        {
            PyErr_Clear();
            return PyErr_Format(PyExc_TypeError, "number not interpretable as C++ int");
        }
        if (fabs(double(val))>1.5E-7 && fabs((double(long(cval))-double(val))/double(val))>1.5E-7)
            return PyErr_Format(PyExc_ValueError, "number not interpretable as C++ int");
        vec.resize(1);
        vec[0] = cval;
    }
    else if (PySequence_Check(args) && !PyUnicode_Check(args))
    {
        vec.resize(PySequence_Size(args));
        for (Py_ssize_t i = 0; i < PySequence_Size(args); i++)
        {
            PyObject *item = PySequence_GetItem(args, i);

            if (!PyNumber_Check(item))
            {
                Py_DECREF(item);
                return PyErr_Format(PyExc_TypeError, "arg %d is not a number type", (int) i);
            }

            long val = PyLong_AsLong(item);
            int cval = int(val);

            if (val == -1 && PyErr_Occurred())
            {
                Py_DECREF(item);
                PyErr_Clear();
                return PyErr_Format(PyExc_TypeError, "arg %d not interpretable as C++ int", (int) i);
            }
            if (fabs(double(val))>1.5E-7 && fabs((double(long(cval))-double(val))/double(val))>1.5E-7)
            {
                Py_DECREF(item);
                return PyErr_Format(PyExc_ValueError, "arg %d not interpretable as C++ int", (int) i);
            }
            Py_DECREF(item);

            vec[i] = cval;
        }
    }
    else
        return PyErr_Format(PyExc_TypeError, "arg(s) must be one or more ints");

    obj->data->GetGraphEdges() = vec;
    // Mark the graphEdges in the object as modified.
    obj->data->SelectGraphEdges();

    Py_INCREF(Py_None);
    return Py_None;
}

/*static*/ PyObject *
avtSubsetsMetaData_GetGraphEdges(PyObject *self, PyObject *args)
{
    avtSubsetsMetaDataObject *obj = (avtSubsetsMetaDataObject *)self;
    // Allocate a tuple the with enough entries to hold the graphEdges.
    const intVector &graphEdges = obj->data->GetGraphEdges();
    PyObject *retval = PyTuple_New(graphEdges.size());
    for(size_t i = 0; i < graphEdges.size(); ++i)
        PyTuple_SET_ITEM(retval, i, PyInt_FromLong(long(graphEdges[i])));
    return retval;
}

/*static*/ PyObject *
avtSubsetsMetaData_SetIsChunkCat(PyObject *self, PyObject *args)
{
    avtSubsetsMetaDataObject *obj = (avtSubsetsMetaDataObject *)self;

    PyObject *packaged_args = 0;

    // Handle args packaged into a tuple of size one
    // if we think the unpackaged args matches our needs
    if (PySequence_Check(args) && PySequence_Size(args) == 1)
    {
        packaged_args = PySequence_GetItem(args, 0);
        if (PyNumber_Check(packaged_args))
            args = packaged_args;
    }

    if (PySequence_Check(args))
    {
        Py_XDECREF(packaged_args);
        return PyErr_Format(PyExc_TypeError, "expecting a single number arg");
    }

    if (!PyNumber_Check(args))
    {
        Py_XDECREF(packaged_args);
        return PyErr_Format(PyExc_TypeError, "arg is not a number type");
    }

    long val = PyLong_AsLong(args);
    bool cval = bool(val);

    if (val == -1 && PyErr_Occurred())
    {
        Py_XDECREF(packaged_args);
        PyErr_Clear();
        return PyErr_Format(PyExc_TypeError, "arg not interpretable as C++ bool");
    }
    if (fabs(double(val))>1.5E-7 && fabs((double(long(cval))-double(val))/double(val))>1.5E-7)
    {
        Py_XDECREF(packaged_args);
        return PyErr_Format(PyExc_ValueError, "arg not interpretable as C++ bool");
    }

    Py_XDECREF(packaged_args);

    // Set the isChunkCat in the object.
    obj->data->isChunkCat = cval;

    Py_INCREF(Py_None);
    return Py_None;
}

/*static*/ PyObject *
avtSubsetsMetaData_GetIsChunkCat(PyObject *self, PyObject *args)
{
    avtSubsetsMetaDataObject *obj = (avtSubsetsMetaDataObject *)self;
    PyObject *retval = PyInt_FromLong(obj->data->isChunkCat?1L:0L);
    return retval;
}

/*static*/ PyObject *
avtSubsetsMetaData_SetIsMaterialCat(PyObject *self, PyObject *args)
{
    avtSubsetsMetaDataObject *obj = (avtSubsetsMetaDataObject *)self;

    PyObject *packaged_args = 0;

    // Handle args packaged into a tuple of size one
    // if we think the unpackaged args matches our needs
    if (PySequence_Check(args) && PySequence_Size(args) == 1)
    {
        packaged_args = PySequence_GetItem(args, 0);
        if (PyNumber_Check(packaged_args))
            args = packaged_args;
    }

    if (PySequence_Check(args))
    {
        Py_XDECREF(packaged_args);
        return PyErr_Format(PyExc_TypeError, "expecting a single number arg");
    }

    if (!PyNumber_Check(args))
    {
        Py_XDECREF(packaged_args);
        return PyErr_Format(PyExc_TypeError, "arg is not a number type");
    }

    long val = PyLong_AsLong(args);
    bool cval = bool(val);

    if (val == -1 && PyErr_Occurred())
    {
        Py_XDECREF(packaged_args);
        PyErr_Clear();
        return PyErr_Format(PyExc_TypeError, "arg not interpretable as C++ bool");
    }
    if (fabs(double(val))>1.5E-7 && fabs((double(long(cval))-double(val))/double(val))>1.5E-7)
    {
        Py_XDECREF(packaged_args);
        return PyErr_Format(PyExc_ValueError, "arg not interpretable as C++ bool");
    }

    Py_XDECREF(packaged_args);

    // Set the isMaterialCat in the object.
    obj->data->isMaterialCat = cval;

    Py_INCREF(Py_None);
    return Py_None;
}

/*static*/ PyObject *
avtSubsetsMetaData_GetIsMaterialCat(PyObject *self, PyObject *args)
{
    avtSubsetsMetaDataObject *obj = (avtSubsetsMetaDataObject *)self;
    PyObject *retval = PyInt_FromLong(obj->data->isMaterialCat?1L:0L);
    return retval;
}

/*static*/ PyObject *
avtSubsetsMetaData_SetIsUnionOfChunks(PyObject *self, PyObject *args)
{
    avtSubsetsMetaDataObject *obj = (avtSubsetsMetaDataObject *)self;

    PyObject *packaged_args = 0;

    // Handle args packaged into a tuple of size one
    // if we think the unpackaged args matches our needs
    if (PySequence_Check(args) && PySequence_Size(args) == 1)
    {
        packaged_args = PySequence_GetItem(args, 0);
        if (PyNumber_Check(packaged_args))
            args = packaged_args;
    }

    if (PySequence_Check(args))
    {
        Py_XDECREF(packaged_args);
        return PyErr_Format(PyExc_TypeError, "expecting a single number arg");
    }

    if (!PyNumber_Check(args))
    {
        Py_XDECREF(packaged_args);
        return PyErr_Format(PyExc_TypeError, "arg is not a number type");
    }

    long val = PyLong_AsLong(args);
    bool cval = bool(val);

    if (val == -1 && PyErr_Occurred())
    {
        Py_XDECREF(packaged_args);
        PyErr_Clear();
        return PyErr_Format(PyExc_TypeError, "arg not interpretable as C++ bool");
    }
    if (fabs(double(val))>1.5E-7 && fabs((double(long(cval))-double(val))/double(val))>1.5E-7)
    {
        Py_XDECREF(packaged_args);
        return PyErr_Format(PyExc_ValueError, "arg not interpretable as C++ bool");
    }

    Py_XDECREF(packaged_args);

    // Set the isUnionOfChunks in the object.
    obj->data->isUnionOfChunks = cval;

    Py_INCREF(Py_None);
    return Py_None;
}

/*static*/ PyObject *
avtSubsetsMetaData_GetIsUnionOfChunks(PyObject *self, PyObject *args)
{
    avtSubsetsMetaDataObject *obj = (avtSubsetsMetaDataObject *)self;
    PyObject *retval = PyInt_FromLong(obj->data->isUnionOfChunks?1L:0L);
    return retval;
}

/*static*/ PyObject *
avtSubsetsMetaData_SetHasPartialCells(PyObject *self, PyObject *args)
{
    avtSubsetsMetaDataObject *obj = (avtSubsetsMetaDataObject *)self;

    PyObject *packaged_args = 0;

    // Handle args packaged into a tuple of size one
    // if we think the unpackaged args matches our needs
    if (PySequence_Check(args) && PySequence_Size(args) == 1)
    {
        packaged_args = PySequence_GetItem(args, 0);
        if (PyNumber_Check(packaged_args))
            args = packaged_args;
    }

    if (PySequence_Check(args))
    {
        Py_XDECREF(packaged_args);
        return PyErr_Format(PyExc_TypeError, "expecting a single number arg");
    }

    if (!PyNumber_Check(args))
    {
        Py_XDECREF(packaged_args);
        return PyErr_Format(PyExc_TypeError, "arg is not a number type");
    }

    long val = PyLong_AsLong(args);
    bool cval = bool(val);

    if (val == -1 && PyErr_Occurred())
    {
        Py_XDECREF(packaged_args);
        PyErr_Clear();
        return PyErr_Format(PyExc_TypeError, "arg not interpretable as C++ bool");
    }
    if (fabs(double(val))>1.5E-7 && fabs((double(long(cval))-double(val))/double(val))>1.5E-7)
    {
        Py_XDECREF(packaged_args);
        return PyErr_Format(PyExc_ValueError, "arg not interpretable as C++ bool");
    }

    Py_XDECREF(packaged_args);

    // Set the hasPartialCells in the object.
    obj->data->hasPartialCells = cval;

    Py_INCREF(Py_None);
    return Py_None;
}

/*static*/ PyObject *
avtSubsetsMetaData_GetHasPartialCells(PyObject *self, PyObject *args)
{
    avtSubsetsMetaDataObject *obj = (avtSubsetsMetaDataObject *)self;
    PyObject *retval = PyInt_FromLong(obj->data->hasPartialCells?1L:0L);
    return retval;
}

/*static*/ PyObject *
avtSubsetsMetaData_SetDecompMode(PyObject *self, PyObject *args)
{
    avtSubsetsMetaDataObject *obj = (avtSubsetsMetaDataObject *)self;

    PyObject *packaged_args = 0;

    // Handle args packaged into a tuple of size one
    // if we think the unpackaged args matches our needs
    if (PySequence_Check(args) && PySequence_Size(args) == 1)
    {
        packaged_args = PySequence_GetItem(args, 0);
        if (PyNumber_Check(packaged_args))
            args = packaged_args;
    }

    if (PySequence_Check(args))
    {
        Py_XDECREF(packaged_args);
        return PyErr_Format(PyExc_TypeError, "expecting a single number arg");
    }

    if (!PyNumber_Check(args))
    {
        Py_XDECREF(packaged_args);
        return PyErr_Format(PyExc_TypeError, "arg is not a number type");
    }

    long val = PyLong_AsLong(args);
    int cval = int(val);

    if ((val == -1 && PyErr_Occurred()) || long(cval) != val)
    {
        Py_XDECREF(packaged_args);
        PyErr_Clear();
        return PyErr_Format(PyExc_TypeError, "arg not interpretable as C++ int");
    }

    if (cval < 0 || cval >= 3)
    {
        std::stringstream ss;
        ss << "An invalid decompMode value was given." << std::endl;
        ss << "Valid values are in the range [0,2]." << std::endl;
        ss << "You can also use the following symbolic names:";
        ss << " None";
        ss << ", Cover";
        ss << ", Partition";
        return PyErr_Format(PyExc_ValueError, ss.str().c_str());
    }

    Py_XDECREF(packaged_args);

    // Set the decompMode in the object.
    obj->data->decompMode = avtSubsetsMetaData::DecompMode(cval);

    Py_INCREF(Py_None);
    return Py_None;
}

/*static*/ PyObject *
avtSubsetsMetaData_GetDecompMode(PyObject *self, PyObject *args)
{
    avtSubsetsMetaDataObject *obj = (avtSubsetsMetaDataObject *)self;
    PyObject *retval = PyInt_FromLong(long(obj->data->decompMode));
    return retval;
}

/*static*/ PyObject *
avtSubsetsMetaData_SetMaxTopoDim(PyObject *self, PyObject *args)
{
    avtSubsetsMetaDataObject *obj = (avtSubsetsMetaDataObject *)self;

    PyObject *packaged_args = 0;

    // Handle args packaged into a tuple of size one
    // if we think the unpackaged args matches our needs
    if (PySequence_Check(args) && PySequence_Size(args) == 1)
    {
        packaged_args = PySequence_GetItem(args, 0);
        if (PyNumber_Check(packaged_args))
            args = packaged_args;
    }

    if (PySequence_Check(args))
    {
        Py_XDECREF(packaged_args);
        return PyErr_Format(PyExc_TypeError, "expecting a single number arg");
    }

    if (!PyNumber_Check(args))
    {
        Py_XDECREF(packaged_args);
        return PyErr_Format(PyExc_TypeError, "arg is not a number type");
    }

    long val = PyLong_AsLong(args);
    int cval = int(val);

    if (val == -1 && PyErr_Occurred())
    {
        Py_XDECREF(packaged_args);
        PyErr_Clear();
        return PyErr_Format(PyExc_TypeError, "arg not interpretable as C++ int");
    }
    if (fabs(double(val))>1.5E-7 && fabs((double(long(cval))-double(val))/double(val))>1.5E-7)
    {
        Py_XDECREF(packaged_args);
        return PyErr_Format(PyExc_ValueError, "arg not interpretable as C++ int");
    }

    Py_XDECREF(packaged_args);

    // Set the maxTopoDim in the object.
    obj->data->maxTopoDim = cval;

    Py_INCREF(Py_None);
    return Py_None;
}

/*static*/ PyObject *
avtSubsetsMetaData_GetMaxTopoDim(PyObject *self, PyObject *args)
{
    avtSubsetsMetaDataObject *obj = (avtSubsetsMetaDataObject *)self;
    PyObject *retval = PyInt_FromLong(long(obj->data->maxTopoDim));
    return retval;
}



PyMethodDef PyavtSubsetsMetaData_methods[AVTSUBSETSMETADATA_NMETH] = {
    {"Notify", avtSubsetsMetaData_Notify, METH_VARARGS},
    {"SetCatName", avtSubsetsMetaData_SetCatName, METH_VARARGS},
    {"GetCatName", avtSubsetsMetaData_GetCatName, METH_VARARGS},
    {"SetCatCount", avtSubsetsMetaData_SetCatCount, METH_VARARGS},
    {"GetCatCount", avtSubsetsMetaData_GetCatCount, METH_VARARGS},
    {"SetNameScheme", avtSubsetsMetaData_SetNameScheme, METH_VARARGS},
    {"GetNameScheme", avtSubsetsMetaData_GetNameScheme, METH_VARARGS},
    {"SetColorScheme", avtSubsetsMetaData_SetColorScheme, METH_VARARGS},
    {"GetColorScheme", avtSubsetsMetaData_GetColorScheme, METH_VARARGS},
    {"SetSetsToChunksMaps", avtSubsetsMetaData_SetSetsToChunksMaps, METH_VARARGS},
    {"GetSetsToChunksMaps", avtSubsetsMetaData_GetSetsToChunksMaps, METH_VARARGS},
    {"SetGraphEdges", avtSubsetsMetaData_SetGraphEdges, METH_VARARGS},
    {"GetGraphEdges", avtSubsetsMetaData_GetGraphEdges, METH_VARARGS},
    {"SetIsChunkCat", avtSubsetsMetaData_SetIsChunkCat, METH_VARARGS},
    {"GetIsChunkCat", avtSubsetsMetaData_GetIsChunkCat, METH_VARARGS},
    {"SetIsMaterialCat", avtSubsetsMetaData_SetIsMaterialCat, METH_VARARGS},
    {"GetIsMaterialCat", avtSubsetsMetaData_GetIsMaterialCat, METH_VARARGS},
    {"SetIsUnionOfChunks", avtSubsetsMetaData_SetIsUnionOfChunks, METH_VARARGS},
    {"GetIsUnionOfChunks", avtSubsetsMetaData_GetIsUnionOfChunks, METH_VARARGS},
    {"SetHasPartialCells", avtSubsetsMetaData_SetHasPartialCells, METH_VARARGS},
    {"GetHasPartialCells", avtSubsetsMetaData_GetHasPartialCells, METH_VARARGS},
    {"SetDecompMode", avtSubsetsMetaData_SetDecompMode, METH_VARARGS},
    {"GetDecompMode", avtSubsetsMetaData_GetDecompMode, METH_VARARGS},
    {"SetMaxTopoDim", avtSubsetsMetaData_SetMaxTopoDim, METH_VARARGS},
    {"GetMaxTopoDim", avtSubsetsMetaData_GetMaxTopoDim, METH_VARARGS},
    {NULL, NULL}
};

static void PyavtSubsetsMetaData_ExtendSetGetMethodTable()
{
    static bool extended = false;
    if (extended) return;
    extended = true;

    int i = 0;
    while (PyavtSubsetsMetaData_methods[i].ml_name)
        i++;
    int n = i;
    while (PyavtVarMetaData_methods[i-n+1].ml_name)
    {
        PyavtSubsetsMetaData_methods[i] = PyavtVarMetaData_methods[i-n+1];
        i++;
    }

    PyMethodDef nullMethod = {NULL, NULL};
    PyavtSubsetsMetaData_methods[i] = nullMethod;
}

//
// Type functions
//

static void
avtSubsetsMetaData_dealloc(PyObject *v)
{
   avtSubsetsMetaDataObject *obj = (avtSubsetsMetaDataObject *)v;
   if(obj->parent != 0)
       Py_DECREF(obj->parent);
   if(obj->owns)
       delete obj->data;
}

static PyObject *avtSubsetsMetaData_richcompare(PyObject *self, PyObject *other, int op);
PyObject *
PyavtSubsetsMetaData_getattr(PyObject *self, char *name)
{
    if(strcmp(name, "catName") == 0)
        return avtSubsetsMetaData_GetCatName(self, NULL);
    if(strcmp(name, "catCount") == 0)
        return avtSubsetsMetaData_GetCatCount(self, NULL);
    if(strcmp(name, "nameScheme") == 0)
        return avtSubsetsMetaData_GetNameScheme(self, NULL);
    if(strcmp(name, "colorScheme") == 0)
        return avtSubsetsMetaData_GetColorScheme(self, NULL);
    if(strcmp(name, "setsToChunksMaps") == 0)
        return avtSubsetsMetaData_GetSetsToChunksMaps(self, NULL);
    if(strcmp(name, "graphEdges") == 0)
        return avtSubsetsMetaData_GetGraphEdges(self, NULL);
    if(strcmp(name, "isChunkCat") == 0)
        return avtSubsetsMetaData_GetIsChunkCat(self, NULL);
    if(strcmp(name, "isMaterialCat") == 0)
        return avtSubsetsMetaData_GetIsMaterialCat(self, NULL);
    if(strcmp(name, "isUnionOfChunks") == 0)
        return avtSubsetsMetaData_GetIsUnionOfChunks(self, NULL);
    if(strcmp(name, "hasPartialCells") == 0)
        return avtSubsetsMetaData_GetHasPartialCells(self, NULL);
    if(strcmp(name, "decompMode") == 0)
        return avtSubsetsMetaData_GetDecompMode(self, NULL);
    if(strcmp(name, "None") == 0)
        return PyInt_FromLong(long(avtSubsetsMetaData::None));
    if(strcmp(name, "NONE") == 0)
        return PyInt_FromLong(long(avtSubsetsMetaData::None));
    if(strcmp(name, "Cover") == 0)
        return PyInt_FromLong(long(avtSubsetsMetaData::Cover));
    if(strcmp(name, "Partition") == 0)
        return PyInt_FromLong(long(avtSubsetsMetaData::Partition));

    if(strcmp(name, "maxTopoDim") == 0)
        return avtSubsetsMetaData_GetMaxTopoDim(self, NULL);

    if(strcmp(name, "__methods__") != 0)
    {
        PyObject *retval = PyavtVarMetaData_getattr(self, name);
        if (retval) return retval;
    }

    PyavtSubsetsMetaData_ExtendSetGetMethodTable();

    // Add a __dict__ answer so that dir() works
    if (!strcmp(name, "__dict__"))
    {
        PyObject *result = PyDict_New();
        for (int i = 0; PyavtSubsetsMetaData_methods[i].ml_meth; i++)
            PyDict_SetItem(result,
                PyString_FromString(PyavtSubsetsMetaData_methods[i].ml_name),
                PyString_FromString(PyavtSubsetsMetaData_methods[i].ml_name));
        return result;
    }

    return Py_FindMethod(PyavtSubsetsMetaData_methods, self, name);
}

int
PyavtSubsetsMetaData_setattr(PyObject *self, char *name, PyObject *args)
{
    if (PyavtVarMetaData_setattr(self, name, args) != -1)
        return 0;
    else
        PyErr_Clear();

    PyObject NULL_PY_OBJ;
    PyObject *obj = &NULL_PY_OBJ;

    if(strcmp(name, "catName") == 0)
        obj = avtSubsetsMetaData_SetCatName(self, args);
    else if(strcmp(name, "catCount") == 0)
        obj = avtSubsetsMetaData_SetCatCount(self, args);
    else if(strcmp(name, "nameScheme") == 0)
        obj = avtSubsetsMetaData_SetNameScheme(self, args);
    else if(strcmp(name, "colorScheme") == 0)
        obj = avtSubsetsMetaData_SetColorScheme(self, args);
    else if(strcmp(name, "setsToChunksMaps") == 0)
        obj = avtSubsetsMetaData_SetSetsToChunksMaps(self, args);
    else if(strcmp(name, "graphEdges") == 0)
        obj = avtSubsetsMetaData_SetGraphEdges(self, args);
    else if(strcmp(name, "isChunkCat") == 0)
        obj = avtSubsetsMetaData_SetIsChunkCat(self, args);
    else if(strcmp(name, "isMaterialCat") == 0)
        obj = avtSubsetsMetaData_SetIsMaterialCat(self, args);
    else if(strcmp(name, "isUnionOfChunks") == 0)
        obj = avtSubsetsMetaData_SetIsUnionOfChunks(self, args);
    else if(strcmp(name, "hasPartialCells") == 0)
        obj = avtSubsetsMetaData_SetHasPartialCells(self, args);
    else if(strcmp(name, "decompMode") == 0)
        obj = avtSubsetsMetaData_SetDecompMode(self, args);
    else if(strcmp(name, "maxTopoDim") == 0)
        obj = avtSubsetsMetaData_SetMaxTopoDim(self, args);

    if (obj != NULL && obj != &NULL_PY_OBJ)
        Py_DECREF(obj);

    if (obj == &NULL_PY_OBJ)
    {
        obj = NULL;
        PyErr_Format(PyExc_NameError, "name '%s' is not defined", name);
    }
    else if (obj == NULL && !PyErr_Occurred())
        PyErr_Format(PyExc_RuntimeError, "unknown problem with '%s'", name);

    return (obj != NULL) ? 0 : -1;
}

static int
avtSubsetsMetaData_print(PyObject *v, FILE *fp, int flags)
{
    avtSubsetsMetaDataObject *obj = (avtSubsetsMetaDataObject *)v;
    fprintf(fp, "%s", PyavtSubsetsMetaData_ToString(obj->data, "",false).c_str());
    return 0;
}

PyObject *
avtSubsetsMetaData_str(PyObject *v)
{
    avtSubsetsMetaDataObject *obj = (avtSubsetsMetaDataObject *)v;
    return PyString_FromString(PyavtSubsetsMetaData_ToString(obj->data,"", false).c_str());
}

//
// The doc string for the class.
//
#if PY_MAJOR_VERSION > 2 || (PY_MAJOR_VERSION == 2 && PY_MINOR_VERSION >= 5)
static const char *avtSubsetsMetaData_Purpose = "Information about a particular category of subsets of a mesh (even for material subsets)";
#else
static char *avtSubsetsMetaData_Purpose = "Information about a particular category of subsets of a mesh (even for material subsets)";
#endif

//
// Python Type Struct Def Macro from Py2and3Support.h
//
//         VISIT_PY_TYPE_OBJ( VPY_TYPE,
//                            VPY_NAME,
//                            VPY_OBJECT,
//                            VPY_DEALLOC,
//                            VPY_PRINT,
//                            VPY_GETATTR,
//                            VPY_SETATTR,
//                            VPY_STR,
//                            VPY_PURPOSE,
//                            VPY_RICHCOMP,
//                            VPY_AS_NUMBER)

//
// The type description structure
//

VISIT_PY_TYPE_OBJ(avtSubsetsMetaDataType,         \
                  "avtSubsetsMetaData",           \
                  avtSubsetsMetaDataObject,       \
                  avtSubsetsMetaData_dealloc,     \
                  avtSubsetsMetaData_print,       \
                  PyavtSubsetsMetaData_getattr,   \
                  PyavtSubsetsMetaData_setattr,   \
                  avtSubsetsMetaData_str,         \
                  avtSubsetsMetaData_Purpose,     \
                  avtSubsetsMetaData_richcompare, \
                  0); /* as_number*/

//
// Helper function for comparing.
//
static PyObject *
avtSubsetsMetaData_richcompare(PyObject *self, PyObject *other, int op)
{
    // only compare against the same type 
    if ( Py_TYPE(self) != &avtSubsetsMetaDataType
         || Py_TYPE(other) != &avtSubsetsMetaDataType)
    {
        Py_INCREF(Py_NotImplemented);
        return Py_NotImplemented;
    }

    PyObject *res = NULL;
    avtSubsetsMetaData *a = ((avtSubsetsMetaDataObject *)self)->data;
    avtSubsetsMetaData *b = ((avtSubsetsMetaDataObject *)other)->data;

    switch (op)
    {
       case Py_EQ:
           res = (*a == *b) ? Py_True : Py_False;
           break;
       case Py_NE:
           res = (*a != *b) ? Py_True : Py_False;
           break;
       default:
           res = Py_NotImplemented;
           break;
    }

    Py_INCREF(res);
    return res;
}

//
// Helper functions for object allocation.
//

static avtSubsetsMetaData *defaultAtts = 0;
static avtSubsetsMetaData *currentAtts = 0;

static PyObject *
NewavtSubsetsMetaData(int useCurrent)
{
    avtSubsetsMetaDataObject *newObject;
    newObject = PyObject_NEW(avtSubsetsMetaDataObject, &avtSubsetsMetaDataType);
    if(newObject == NULL)
        return NULL;
    if(useCurrent && currentAtts != 0)
        newObject->data = new avtSubsetsMetaData(*currentAtts);
    else if(defaultAtts != 0)
        newObject->data = new avtSubsetsMetaData(*defaultAtts);
    else
        newObject->data = new avtSubsetsMetaData;
    newObject->owns = true;
    newObject->parent = 0;
    return (PyObject *)newObject;
}

static PyObject *
WrapavtSubsetsMetaData(const avtSubsetsMetaData *attr)
{
    avtSubsetsMetaDataObject *newObject;
    newObject = PyObject_NEW(avtSubsetsMetaDataObject, &avtSubsetsMetaDataType);
    if(newObject == NULL)
        return NULL;
    newObject->data = (avtSubsetsMetaData *)attr;
    newObject->owns = false;
    newObject->parent = 0;
    return (PyObject *)newObject;
}

///////////////////////////////////////////////////////////////////////////////
//
// Interface that is exposed to the VisIt module.
//
///////////////////////////////////////////////////////////////////////////////

PyObject *
avtSubsetsMetaData_new(PyObject *self, PyObject *args)
{
    int useCurrent = 0;
    if (!PyArg_ParseTuple(args, "i", &useCurrent))
    {
        if (!PyArg_ParseTuple(args, ""))
            return NULL;
        else
            PyErr_Clear();
    }

    return (PyObject *)NewavtSubsetsMetaData(useCurrent);
}

//
// Plugin method table. These methods are added to the visitmodule's methods.
//
static PyMethodDef avtSubsetsMetaDataMethods[] = {
    {"avtSubsetsMetaData", avtSubsetsMetaData_new, METH_VARARGS},
    {NULL,      NULL}        /* Sentinel */
};

static Observer *avtSubsetsMetaDataObserver = 0;

std::string
PyavtSubsetsMetaData_GetLogString()
{
    std::string s("avtSubsetsMetaData = avtSubsetsMetaData()\n");
    if(currentAtts != 0)
        s += PyavtSubsetsMetaData_ToString(currentAtts, "avtSubsetsMetaData.", true);
    return s;
}

static void
PyavtSubsetsMetaData_CallLogRoutine(Subject *subj, void *data)
{
    typedef void (*logCallback)(const std::string &);
    logCallback cb = (logCallback)data;

    if(cb != 0)
    {
        std::string s("avtSubsetsMetaData = avtSubsetsMetaData()\n");
        s += PyavtSubsetsMetaData_ToString(currentAtts, "avtSubsetsMetaData.", true);
        cb(s);
    }
}

void
PyavtSubsetsMetaData_StartUp(avtSubsetsMetaData *subj, void *data)
{
    if(subj == 0)
        return;

    currentAtts = subj;
    PyavtSubsetsMetaData_SetDefaults(subj);

    //
    // Create the observer that will be notified when the attributes change.
    //
    if(avtSubsetsMetaDataObserver == 0)
    {
        avtSubsetsMetaDataObserver = new ObserverToCallback(subj,
            PyavtSubsetsMetaData_CallLogRoutine, (void *)data);
    }

}

void
PyavtSubsetsMetaData_CloseDown()
{
    delete defaultAtts;
    defaultAtts = 0;
    delete avtSubsetsMetaDataObserver;
    avtSubsetsMetaDataObserver = 0;
}

PyMethodDef *
PyavtSubsetsMetaData_GetMethodTable(int *nMethods)
{
    *nMethods = 1;
    return avtSubsetsMetaDataMethods;
}

bool
PyavtSubsetsMetaData_Check(PyObject *obj)
{
    return (obj->ob_type == &avtSubsetsMetaDataType);
}

avtSubsetsMetaData *
PyavtSubsetsMetaData_FromPyObject(PyObject *obj)
{
    avtSubsetsMetaDataObject *obj2 = (avtSubsetsMetaDataObject *)obj;
    return obj2->data;
}

PyObject *
PyavtSubsetsMetaData_New()
{
    return NewavtSubsetsMetaData(0);
}

PyObject *
PyavtSubsetsMetaData_Wrap(const avtSubsetsMetaData *attr)
{
    return WrapavtSubsetsMetaData(attr);
}

void
PyavtSubsetsMetaData_SetParent(PyObject *obj, PyObject *parent)
{
    avtSubsetsMetaDataObject *obj2 = (avtSubsetsMetaDataObject *)obj;
    obj2->parent = parent;
}

void
PyavtSubsetsMetaData_SetDefaults(const avtSubsetsMetaData *atts)
{
    if(defaultAtts)
        delete defaultAtts;

    defaultAtts = new avtSubsetsMetaData(*atts);
}

